package com.haoyu;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Engine {

    public static Duration parseDuration(String line) {
        Pattern pattern = Pattern.compile("(\\d{1,2}):(\\d{2})\\s*$");
        Matcher m = pattern.matcher(line);
        String minute = "", second = "";
        if (m.find()) {
            minute = m.group(1);
            second = m.group(2);
            return new Duration(minute,second);
        } else {
            return new Duration();
        }

    }


    public static Duration add (List<Duration> songs) {
        int totalSecond = 0;
        for(Duration duration:songs) {
            totalSecond += duration.getSecond() + duration.getMinute() * 60;
        }

        int minute,second;
        minute = totalSecond / 60;
        second = totalSecond % 60;
        return new Duration(minute, second);
    }

}
